home *** CD-ROM | disk | FTP | other *** search
- /* a HyperCard XFCN that joins together (catenates, concatenates)
- * a chosen set of text files, by giving the user std files dialog
- * repeatedly -- first to pick the 'base' file, then to pick those
- * other files to append to the end of the 'base' file....
- *
- * call it as HyperTalk function: catFiles (x0, y0)
- *
- * where x0, y0 are the screen coordinates to base the dialog boxes
- * on ... 0,0 works for a Mac Plus....
- *
- * make it XFCN number 2222 and name it "catFiles"
- *
- * 871222 ^z
- */
-
-
- #include <MacTypes.h>
- #include <OSUtil.h>
- #include <FileMgr.h>
- #include <StdFilePkg.h>
- #include <WindowMgr.h>
- #include <HyperXCmd.h>
-
- pascal void main (XCmdBlockPtr paramPtr);
- int GetFileZ (Str255 *fn, int *vRef, int x0, int y0);
- void pStrCopy (char *p1, char *p2);
- void appendFile (int refNum0, Str255 *fnX, int vRefX);
- long atol (char *s);
-
- /* set up buffer of size 25,600 bytes (= 512 * 50) for copying through;
- * ZBUFSIZ must be an integer, < 32768
- */
- #define ZBUFSIZ 25600
-
-
- pascal void main (paramPtr)
- XCmdBlockPtr paramPtr;
- {
- WindowRecord w_record;
- WindowPtr info_window;
- Rect b_rect;
- Str255 fn0, fnX;
- int vRef0, vRefX, refNum0, x0, y0;
-
- if (paramPtr->paramCount != 2)
- {
- SysBeep (10);
- return;
- }
- x0 = atol (*(paramPtr->params[0]));
- y0 = atol (*(paramPtr->params[1]));
-
- b_rect.top = 30 + y0;
- b_rect.left = 12 + x0;
- b_rect.bottom = 52 + y0;
- b_rect.right = 500 + x0;
- info_window = NewWindow (&w_record, &b_rect, "\p", (Boolean)1, dBoxProc,
- (WindowPtr)-1, (Boolean)0, (long)0);
- ShowWindow (info_window);
- SetPort (info_window);
- TextFont (0);
- b_rect.top = 0;
- b_rect.left = 0;
- b_rect.bottom = 22;
- b_rect.right = 488;
-
- EraseRect (&b_rect);
- MoveTo ( 4,15);
- DrawString ("\pChoose a base file -- other files will be appended to it.");
-
- if (GetFileZ (&fn0, &vRef0, x0, y0))
- {
- if (FSOpen (fn0, vRef0, &refNum0) != noErr)
- {
- SysBeep (10);
- CloseWindow (info_window);
- return;
- }
- EraseRect (&b_rect);
- MoveTo (4, 15);
- DrawString ("\pChoose files to append to the base -- 'Cancel' when done.");
- while (GetFileZ (&fnX, &vRefX, x0, y0))
- appendFile (refNum0, &fnX, vRefX);
- FSClose (refNum0);
- }
-
- CloseWindow (info_window);
- return;
- }
-
-
- /* following variables and routine do the standard files dialog
- * to get the name of the file to use ... cribbed from the MiniEdit
- * example that comes with LSC.... put the dialog box someplace
- * reasonable, nothing complex ....
- */
-
- int GetFileZ (fnp, vRefp, x0, y0)
- Str255 *fnp;
- int *vRefp, x0, y0;
- {
- SFTypeList myTypes;
- Point SFGwhere;
- SFReply reply;
-
- SFGwhere.v = 90 + y0;
- SFGwhere.h = 82 + x0;
- myTypes[0] = 'TEXT';
-
- SFGetFile( SFGwhere, "\p", 0L, 1, myTypes, 0L, &reply);
-
- if (reply.good)
- {
- pStrCopy( (char *)reply.fName, (char *)fnp);
- *vRefp = reply.vRefNum;
- return (1);
- }
- else return (0);
- }
-
-
- /* routine to copy a pascal string from one place to another.... used in
- * above Standard Files routine.... from LSC library....
- */
-
- void pStrCopy (p1, p2 )
- register char *p1, *p2;
- {
- register int len;
-
- len = *p2++ = *p1++;
- while (--len >= 0)
- *p2++ = *p1++;
- return;
- }
-
-
- /* routine to append the contents of file X to file 0....does some real
- * simple error checking and (because of constraints while working within
- * HyperCard, and my naivete) just beeps and closes the current file if
- * an error is found....
- */
-
- void appendFile (refNum0, fnXp, vRefX)
- int refNum0, vRefX;
- Str255 *fnXp;
- {
- int refNumX, err;
- long count;
- char buf[ZBUFSIZ];
-
- if (FSOpen (fnXp, vRefX, &refNumX) != noErr)
- {
- SysBeep (10);
- FSClose (refNumX);
- return;
- }
- if (SetFPos (refNumX, fsFromStart, 0L) != noErr)
- {
- SysBeep (10);
- FSClose (refNumX);
- return;
- }
- if (SetFPos (refNum0, fsFromLEOF, 0L) != noErr)
- {
- SysBeep (10);
- FSClose (refNumX);
- return;
- }
- for (;;)
- {
- count = ZBUFSIZ;
- err = FSRead (refNumX, &count, buf);
- if (err != noErr && err != eofErr)
- {
- SysBeep (10);
- FSClose (refNumX);
- return;
- }
- if (count == 0)
- break;
- if (FSWrite (refNum0, &count, buf) != noErr)
- {
- SysBeep (10);
- FSClose (refNumX);
- return;
- }
- }
- FSClose (refNumX);
- return;
- }
-
-
- /* function to convert alphabetic string to a long integer ... from LSC
- * library.... simplified to avoid using isspace() & isdigit() ....
- */
-
- long atol (s)
- register char *s;
- {
- register char signflag = 0;
- register long r = 0;
-
- while ((*s == ' '))
- s++;
-
- if (*s == '-')
- {
- signflag = 1;
- s++;
- }
- else if (*s == '+')
- s++;
-
- while (*s >= '0' && *s <= '9')
- r = r * 10 + (*s++ - '0');
-
- return (signflag ? -r : r);
- }
-
-
-
-
-